$(document).ready(function() {
        var playing = false;
        var mousedown = false;

        document.onmousedown = function() { return false; }
	
        $("#playbutton").click(function() {
                if(playing) {
                    // Pause
                    $("#playbtn").attr("src", "btn-play.png");
                    playing = false;
                    $("#vinyl").each(function() {
                            var intervalHandle = $(this).data('intervalHandle');
                            clearInterval(intervalHandle);
                            $(this)
                                .css({ 'cursor' : 'default' })
                                .stop()
                                .animate({rotate: '+=40deg'}, 800, 'easeOutCubic');
                        });

                    player.pause();
                } else {
                    // Play
                    $("#playbtn").attr("src", "btn-pause.png");
                    playing = true;
                    $("#vinyl").each(function() {
                            $(this).data('rotationAngle', 10);
                            startSpinning($(this));
                        });

                    player.play();
                }
            });
	
        function startSpinning(element) {
            element.stop().animate({rotate: '+=40deg'}, 800, 'easeInCubic', function() {
                    var intervalHandle = setInterval(
                        function () {
                            element.animate({rotate: '+=' + element.data('rotationAngle') + 'deg'}, 0);
                        },
                        25
                        );
                    element.data('intervalHandle', intervalHandle);
                });
        }
    });
